<?php

use Swof\Container\Container;

if (! function_exists('app')) {
    /**
     * Get the available container instance.
     *
     * @param string|null $abstract
     * @param array $parameters
     * @return mixed
     */
    function app(string $abstract = null, array $parameters = [])
    {
        if (is_null($abstract)) {
            return Container::getInstance();
        }

        return Container::getInstance()->make($abstract, $parameters);
    }
}

if (! function_exists('dd')) {
    function dd(...$args) {
        echo PHP_EOL . PHP_EOL . PHP_EOL;
        echo '-------打印开始-------' . PHP_EOL;
        foreach ($args as $x) {
            if (is_string($x)) {
                echo $x;
                echo PHP_EOL;
            } else {
                print_r($x) . PHP_EOL;
            }
        }
        echo '-------打印结束-------' . PHP_EOL;
        echo PHP_EOL . PHP_EOL . PHP_EOL;
    }
}

if (! function_exists('config')) {
    /**
     * Get / set the specified configuration value.
     *
     * If an array is passed as the key, we will assume you want to set an array of values.
     *
     * @param array|string|null $key
     * @param mixed $default
     * @return mixed|\Swof\Config\Repository
     */
    function config($key = null, $default = null)
    {
        if (is_null($key)) {
            return app('config');
        }

        if (is_array($key)) {
            return app('config')->set($key);
        }

        return app('config')->get($key, $default);
    }
}
